<style scoped lang="scss"></style>
<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";
	import {
		searchDataZzgz
	} from "@/api/search";
	import {
		addOrUpdateZzgz
	} from "@/api/addOrUpdate";
	import { postTableData } from "@/api/table";


	const city = window.globalObj.name;
	const editorRef = shallowRef();

	const toolbarConfig = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");

	// 加载html
	const initHtml = () => {
		searchDataZzgz({
			m: "附件"
		}).then((res) => {
			const {
				data
			} = res
			valueHtml.value = data.find((x) => x.k === "附件")?.v || "";
		})
	};

	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};

	const valueHtml = ref(
		"主要包括总体构想图、力量部署图、指挥流程图和指挥机构编成表、力量编成表、重要目标统计表等。<br/>1.某某市政治工作统筹图<br/>2.某某市心理防护力量编成表"
	);

	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateZzgz({
					m: "附件",
					data: [{
							k: "附件",
							v: valueHtml.value,
						}
					],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}

	
	onBeforeUnmount(() => {
		const editor = editorRef.value;
		if (!editor) return;
		editor.destroy();

	});
	
	
	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};
	
	
	const tableData = ref([])
	const getList = () => {
		postTableData({
			docType: "politicalwork",
			method: "xinlifanghuliliangbiancheng",
		}).then(result=>{
			if(result.code === 200){
				tableData.value = result.data
			}
		})
	}
	
	
	
	onMounted(() => {
		initHtml();
		getList()
	
	});
	
	
</script>
<template>
	<div class="">
		<FirstTitle name="附件" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		
		<FirstTitle name="政治工作统筹图" class="top-15" />
		<div style="width: 100%;height: auto" class="top-15">
			<img style="width: 100%; height: 100%;" src="../img/tct.png" alt="" mode="widthFix" />
		</div>
		
		
		<FirstTitle name="心理防护力量编成" class="top-15" />
		<div class="top-15  text-center">{{ city }}心理防护力量编成表</div>
		<el-table id="table" :data="tableData" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="100" align="center" />
			<el-table-column prop="type_x" label="专业队名称" />
			<el-table-column prop="address" label="单位地址" />
			<el-table-column prop="qtdw" label="牵头单位" />
			<el-table-column prop="num" label="人数(人)" />
		</el-table>
		

		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>